#!/usr/bin/env python3  /*设定脚本文件直接能执行*/
# -*- coding:utf-8 -*-   /*设置编码*/
"""
@Author: WANDERSON M.PIMENTA
@Software: PyCharm 、Qt Designer and PySide6
@File: tQLeftColumnIcon.py
@Time: 2024/05/11 16:35
@Function：ctQLeftColumnIcon：左侧列的图标（设置 & 信息顶部图标）
"""
from tQQtCore import *


# ctQLeftColumnIcon：左侧列的图标（设置 & 信息顶部图标）
class ctQLeftColumnIcon(QWidget):
    # 初始化
    def __init__(self,
                 icon_path,
                 icon_color
                 ):
        super().__init__()

        # 属性
        self._icon_path = icon_path
        self._icon_color = icon_color

        # 左侧列Icon布局函数
        self.__f_leftColumnIconLayout()

    # 左侧列设置图标函数
    def f_leftColumnSetIcon(self, icon_path, icon_color=None):
        """
        function:  左侧列设置图标函数
              in:  icon_path：icon的路径
                   icon_path：icon的颜色
             out:  None
          return:  None
          others:  The Left Column Set Icon Func
        """
        # GET COLOR
        color = ""
        if icon_color is not None:
            color = icon_color
        else:
            color = self._icon_color

        # PAINTER / PIXMAP
        icon = QPixmap(icon_path)
        painter = QPainter(icon)
        painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
        painter.fillRect(icon.rect(), color)
        painter.end()

        # SET PIXMAP
        self.icon.setPixmap(icon)

    # <editor-fold desc="该类用到的私有方法">
    # 左侧列Icon布局函数
    def __f_leftColumnIconLayout(self):
        # LAYOUT
        self.layout = QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)

        # LABEL
        self.icon = QLabel()
        self.icon.setAlignment(Qt.AlignCenter)

        # 左侧列设置图标函数
        self.f_leftColumnSetIcon(self._icon_path, self._icon_color)

        # ADD TO LAYOUT
        self.layout.addWidget(self.icon)
    # </editor-fold>
